/**
 * Project Name:StudentRouter.java
 * File Name:StudentRouter.java
 * Date:2019-03-04 22:17
 * Copyright (c) 2019, zhang.xiangyu@foxmail.com All Rights Reserved.
 */
package com.meatball.student.router;

import com.meatball.student.handler.StudentHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.web.reactive.function.server.RequestPredicates.*;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;

/**
 * @Title: StudentRouter.java
 * @Description: todo(接口层)
 * @Author: 張翔宇
 * @Date: 2019-03-04 22:17
 * @Version: V1.0
 */
@Configuration
public class StudentRouter {

    private final StudentHandler handler;

    public StudentRouter (StudentHandler handler) {
        this.handler = handler;
    }

    @Bean
    public RouterFunction<ServerResponse> student() {
        return route()
            .path("/student", builder -> builder
                // 查询列表
                .GET("", handler::selectStudent)
                // 根据ID查询
                .GET("/{id}", handler::selectById)
                // 新增
                .POST("",accept(MediaType.APPLICATION_JSON), handler::insertStudent))
            .build();
    }
}
